package me.zk.practice1.hw;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

/**
 * @author zhangkai
 * @date 2023/8/10 13:48
 */
public class HWBJJ06 {
    //4
    //A,C,C,F
    //C,D,E,D
    //B,E,S,S
    //F,E,C,A
    //ACCESS
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());

        String[][] str = new String[n][n];

        for (int i = 0; i < n; i++) {
            String[] chs =scanner.nextLine().split(",");
            for (int j = 0; j < n; j++) {
                str[i][j] = chs[j];
            }
        }
        String word = scanner.nextLine();
        boolean flag = false;
        boolean[][] used = new boolean[n][n];
        List<int[]> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                flag = check(str,word,0,i,j,used, list);
                if (flag) {
                    break;
                }
            }
            if (flag) {
                break;
            }
        }
        if (flag) {
            Collections.reverse(list);
            StringBuilder sb = new StringBuilder();
            for (int[] arr : list) {
                for (int i : arr) {
                    sb.append(i+",");
                }
            }
            System.out.println(sb.substring(0,sb.length()-1));
        } else {
            System.out.println("N");
        }



    }
    static int[][] direction = new int[][]{{0,1},{0,-1},{1,0},{-1,0}};
    public static boolean check(String[][] str, String word, int index, int i, int j,
                                boolean[][] used, List<int[]> list) {
        int[] arr = new int[]{i,j};
        if (!str[i][j].equals(String.valueOf(word.charAt(index)))) {
            return false;
        } else if (index == word.length()-1) {
            list.add(arr);
            return true;
        }
        used[i][j] = true;
        boolean result = false;
        for (int[] dir : direction) {
            int ni = i+dir[0];
            int nj = j+dir[1];
            if (ni >=0 && nj>=0&&ni<str.length&&nj<str[0].length ) {
                if (!used[ni][nj]) {
                    boolean flag = check(str,word,index+1,ni,nj,used,list);
                    if (flag) {
                        result = true;
                        list.add(arr);
                        break;
                    } else {
                        list.remove(arr);
                    }
                }

            }


        }

        used[i][j] = false;
        return result;
    }
}
